﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Xna.Framework;

namespace HelloXNA3.Components._3D.Polygon.Position
{
    public class TwentyPolygonPosition
    {
        public static double X
        {
            get
            {
                return 0.5 / Math.Tan(ConvertToRadians(36));
            }
        }

        public static double Y
        {
            get
            {
                return 0.5 / Math.Sin(ConvertToRadians(36));
            }
        }

        public static double D
        {
            get
            {
                
                return Math.Sqrt(Y * Y - X * X);
            }
        }

        public static double H1
        {
            get
            {
                return Math.Sqrt(3d / 4 - X * X);
            }
        }


        public static double H2
        {
            get
            {
                return Math.Sqrt(3d / 4 - D * D);
            }
        }

        public const float scale = 2.5f;

        public static Vector3[] Corners = new Vector3[]
        {
            new Vector3( 0, (float)(H2/2 + H1) * scale, 0),

            new Vector3( 0, (float)(H2/2) * scale, (float)((-1)*Y)*scale),
            new Vector3( (float)(Y * Math.Cos(ConvertToRadians(18))) * scale, (float)(H2/2)*scale, (float)((-1) * Y * Math.Sin(ConvertToRadians(18))) * scale),
            new Vector3( 0.5f * scale, (float)(H2/2) * scale, (float)X * scale),
            new Vector3( (-1)*0.5f * scale, (float)(H2/2) * scale, (float)X * scale),
            new Vector3( (float)(Y * Math.Cos(ConvertToRadians(18)))*(-1) * scale, (float)(H2/2)*scale, (float)((-1) * Y * Math.Sin(ConvertToRadians(18))) * scale),

            new Vector3( 0, (float)(H2/2) * (-1) * scale, (float)Y * scale),
            new Vector3( (float)(Y * Math.Cos(ConvertToRadians(18))) * scale, (float)(H2/2)*(-1)*scale, (float)( Y * Math.Sin(ConvertToRadians(18))) * scale),
            new Vector3( 0.5f * scale, (float)(H2/2) * (-1) * scale, (float)X * (-1) * scale),
            new Vector3( (-1)*0.5f * scale, (float)(H2/2) * (-1) * scale, (float)X * (-1) * scale),
            new Vector3( (float)(Y * Math.Cos(ConvertToRadians(18)))*(-1) * scale, (float)(H2/2) * (-1) *scale, (float)( Y * Math.Sin(ConvertToRadians(18))) * scale),
           
             new Vector3( 0, (float)(H2/2 + H1) *(-1) * scale, 0),
        };

        // 概率为 C(4,3) 我们会产生4个面
        public static int[][] Faces = new int[][]
        {
            new int[]{ 0, 1, 2 },
            new int[]{ 0, 2, 3 },
            new int[]{ 0, 3, 4 },
            new int[]{ 0, 4, 5 },
            new int[]{ 0, 5, 1 },

            //new int[]{ 1, 5, 9 },
            //new int[]{ 1, 9, 8 },
            //new int[]{ 1, 8, 2 },
            //new int[]{ 2, 7,8 },

            //new int[]{ 2, 3, 7 },
            //new int[]{ 7, 3, 6 },
            //new int[]{ 6, 3, 4 },
            //new int[]{ 4, 6, 10 },
            //new int[]{ 10, 4, 5 },
            //new int[]{ 5, 10, 9 },
            new int[]{ 1, 5, 9 },
            new int[]{ 1, 9, 8 },
            new int[]{ 1, 8, 2 },
            new int[]{ 8, 7, 2 },
            new int[]{ 2, 7, 3 },
            new int[]{ 7, 6, 3 },
            new int[]{ 6, 4, 3 },
            new int[]{ 6, 10, 4 },
            new int[]{ 10, 5, 4 },
            new int[]{ 10, 9, 5 },



            new int[]{ 9, 10, 11 },
            new int[]{ 9, 11, 8 },
            new int[]{ 8, 11, 7 },
            new int[]{ 7, 11, 6 },
            new int[]{ 6, 11, 10 },
        };

        public static double ConvertToRadians(double d)
        {
            return d * Math.PI / 180;
        }
    }
}
